package com.ke.jdyd.http;

import android.app.Application;
import android.widget.Toast;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public abstract class HttpResultObservable<T> implements Observer<BaseResponse<T>> {
  @Override
  public void onSubscribe(Disposable d) {

  }

  @Override
  public void onNext(BaseResponse<T> response) {
    if (response != null) {
      if (response.getCode() == 1000) {
        onSuccess(response.getInfo());
      } else {
        onSuccess(response.getInfo(), response.getCode(), response.getMsg());
      }
    } else {
      onFailed("请求返回异常");
    }

  }

  @Override
  public void onError(Throwable e) {
    onFailed(e.getMessage());
  }

  @Override
  public void onComplete() {

  }
  public abstract void onSuccess(T result);
  public abstract void onSuccess(T result, int code, String msg);
  public abstract void onFailed(String msg);
}
